

--default state for 'Discard Mapping Coords'
noMapCoordsChecked = false
--maxobject
theObject =$
theMsFile = createFile @"D:\jinchenyu\Desktop\aaa.ms"




format "\tfunction buildTriMesh =\n" to:theMsFile
format "\t(\n" to:theMsFile
theMesh = snapShotAsMesh theObject
move theMesh -theObject.pos
theOldOption = options.printAllElements
options.printAllElements = true
format "\t\tv_arr =  %\n" (for i = 1 to getNumVerts theMesh collect getVert theMesh i) to:theMsFile
format "\t\tf_arr =  %\n" (for i = 1 to getNumFaces theMesh collect getFace theMesh i) to:theMsFile
format "\t\tsetMesh theTriMesh verts:v_arr faces:f_arr\n" to:theMsFile
theEdgeVis = for f = 1 to getNumFaces theMesh where not (ba = (for i = 1 to 3 \
	where not getEdgeVis theMesh f i collect i) as bitArray).isEmpty collect #(f, ba)
theSmoothGroups = for f = 1 to getNumFaces theMesh collect getFaceSmoothGroup theMesh f
theMatIDs = for f = 1 to getNumFaces theMesh collect getFaceMatID theMesh f
format "\t\ttheEdgeVis = %\n" theEdgeVis to:theMsFile
format "\t\ttheSmoothGroups = %\n" theSmoothGroups to:theMsFile
format "\t\ttheMatIDs = %\n" theMatIDs to:theMsFile
if not noMapCoordsChecked do
(
	local theNumMaps = meshOp.getNumMaps theMesh
	format "\t\ttheNumMaps = %\n" theNumMaps to:theMsFile
	local theMapSupport = #()
	local theNumMapVerts = #()
	local theNumMapFaces = #()
	local theMapVerts = #()
	local theMapFaces = #()
	for n = 0 to theNumMaps - 1 do
	(
		local supp = meshOp.getMapSupport theMesh n
		append theMapSupport supp
		if supp then
		(
			local numMV = meshOp.getNumMapVerts theMesh n
			local numMF = meshOp.getNumMapFaces theMesh n
			append theNumMapVerts numMV
			append theNumMapFaces numMF
			append theMapVerts (for v = 1 to numMV collect meshOp.getMapVert theMesh n v)
			append theMapFaces (for v = 1 to numMF collect meshOp.getMapFace theMesh n v)
		)
		else
		(
			append theNumMapVerts undefined
			append theNumMapFaces undefined
			append theMapVerts undefined
			append theMapFaces undefined
		)
	)
	format "\t\ttheMapSupport = %\n" theMapSupport to:theMsFile
	format "\t\ttheNumMapVerts = %\n" theNumMapVerts to:theMsFile
	format "\t\ttheNumMapFaces = %\n" theNumMapFaces to:theMsFile
	format "\t\ttheMapVerts = #()\n" to:theMsFile
	format "\t\ttheMapFaces = #()\n" to:theMsFile
	for n = 1 to theNumMaps do
	(
		format "\t\ttheMapVerts[%] = %\n" n theMapVerts[n]  to:theMsFile
		format "\t\ttheMapFaces[%] = %\n" n theMapFaces[n]  to:theMsFile
	)
)
format "\t\tfor f in theEdgeVis do for i in f[2] do\n" to:theMsFile
format "\t\t\tsetEdgeVis theTriMesh f[1] i false\n" to:theMsFile
format "\t\tfor f = 1 to getNumFaces theTriMesh do\n" to:theMsFile
format "\t\t(\n" to:theMsFile
format "\t\t\tsetFaceSmoothGroup theTriMesh f theSmoothGroups[f]\n" to:theMsFile
format "\t\t\tsetFaceMatID theTriMesh f theMatIDs[f]\n" to:theMsFile
format "\t\t)\n" to:theMsFile
if not noMapCoordsChecked do
(
	format "\t\tmeshOp.setNumMaps theTriMesh theNumMaps keep:false\n" to:theMsFile
	format "\t\tfor n = 1 to theNumMaps do\n" to:theMsFile
	format "\t\t(\n" to:theMsFile
	format "\t\t\tlocal supp = theMapSupport[n]\n" to:theMsFile
	format "\t\t\tmeshOp.setMapSupport theTriMesh (n - 1) supp\n" to:theMsFile
	format "\t\t\tif supp do\n" to:theMsFile
	format "\t\t\t(\n" to:theMsFile
	format "\t\t\t\tlocal numMV = theNumMapVerts[n]\n" to:theMsFile
	format "\t\t\t\tlocal numMF = theNumMapFaces[n]\n" to:theMsFile
	format "\t\t\t\tmeshOp.setNumMapVerts theTriMesh (n - 1) numMV\n" to:theMsFile
	format "\t\t\t\tmeshOp.setNumMapFaces theTriMesh (n - 1) numMF\n" to:theMsFile
	format "\t\t\t\tfor v = 1 to numMV do\n" to:theMsFile
	format "\t\t\t\t\tmeshOp.setMapVert theTriMesh (n - 1) v theMapVerts[n][v]\n" to:theMsFile
	format "\t\t\t\tfor f = 1 to numMF do\n" to:theMsFile
	format "\t\t\t\t\tmeshOp.setMapFace theTriMesh (n - 1) f theMapFaces[n][f]\n" to:theMsFile
	format "\t\t\t)\n" to:theMsFile
	format "\t\t)\n" to:theMsFile
)


close theMsFile











